{{template "layout/layout_admin.html" .}}

{{define "style"}}

{{end}}
{{define "content"}}

<div class="layui-fluid main" style="margin:15px;">


    <fieldset class="layui-elem-field layui-field-title" style="margin-top:20px;">
        <legend>业务线</legend>
    </fieldset>

    <div class="kit-table">
        <form class="layui-form" lay-filter="kit-search-form">
            <div class="kit-table-header">
                <div class="kit-search-btns">
                    <a href="{{urlfor "MainController.AppsInsert"}}" data-action="add" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe608;</i> 添加业务线</a>
                </div>
                <div class="kit-search-inputs">

                </div>
            </div>
        </form>
    </div>
    <table id="main_table" lay-filter="main_table"></table>

</div>

{{end}}


{{define "script"}}
<script type="text/html" id="tableTool">
    <!--<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="bind">查看</a>-->
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script>

    var inArray = function(fstr){
        var arr = mcIds
        var i = arr.length;
        while (i--) {
            if (arr[i] == fstr) {
                return "checked";
            }
        }
        return "";
    }
    juicer.register('inArray', inArray);

    layui.use(['jquery','table','form'], function() {
    {{template "layout/baseJs.html" .}}
        var table = layui.table,
                $ = layui.jquery,
                form = layui.form,
                layer = layui.layer,
                laytpl = layui.laytpl;



        table.render({
            elem: '#main_table'
            ,height: 550
            ,url: '{{urlfor "MainController.AppsListApi"}}' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
                ,{field: 'name', title: '业务线名称'}
                ,{field: 'appid', title: 'APPID'}
                ,{field: 'appkey', title: 'APPKEY', width:280}
                ,{field: 'updated_at', title: '最后修改',width:250}
                ,{fixed: 'right', title: '操作', width:160, align:'center', toolbar: '#tableTool'}
            ]]
        });

        //监听工具条
        table.on('tool(main_table)', function(obj){
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event;
            var tr = obj.tr;

            if(layEvent === 'del'){ //删除
                layer.confirm('确认删除['+data.name+"]?", function(index){
                    layer.close(index);

                    var url='{{urlfor "MainController.AppsDelDo"}}';
                    layer.load(2);
                    $.ajax({
                        type: "POST",
                        url: url,
                        data: {id:data.id},
                        success: function(json){
                            layer.closeAll('loading');
                            if(json.status != 200){
                                QI.errorAlert(json.info);
                                return false;
                            }
                            QI.successAlert(json.info);
                            QI.delayJump('');
                        },
                        error:function(e){
                            layer.closeAll('loading');
                            QI.errorAlert('系统出小差了（'+e.statusText+'）');
                        }
                    });
                });



            } else if(layEvent === 'edit'){ //编辑
                location.href='{{urlfor "MainController.AppsEdit"}}?id='+data.id;
            }
        });


    });
</script>

{{end}}
